<?php
/**
 * Model_Categories 分类模型
 *
 * @package Movoin Blog
 * @subpackage Model
 *
 */

class Model_Categories
{

    /**
     * tblCategory
     *
     * @var mixed
     * @access public
     */
    var $tblCategory;

    /**
     * Model_Categories
     *
     * @access public
     * @return void
     */
    function Model_Categories()
    {
        $this->tblCategory = & FLEA::getSingleton('Table_Categories');
    }

    /**
     * getCategories
     *
     * @param string $fields
     * @param string $orderby
     * @param mixed $links
     * @access public
     * @return void
     */
    function getCategories($fields='*', $orderby='sort_id ASC, cate_id ASC', $links=false){
        return $this->tblCategory->findAll(null, $orderby, null, $fields, $links);
    }

    /**
     * getCategory
     *
     * @param mixed $cate_id
     * @param string $fields
     * @param string $orderby
     * @param mixed $links
     * @access public
     * @return void
     */
    function getCategory($cate_id=null, $fields='*', $orderby='sort_id ASC, cate_id ASC', $links=false){
        return $this->tblCategory->find($cate_id,$orderby,$fields,$links);
    }

    /**
     * createCategory
     *
     * @param mixed $data
     * @access public
     * @return void
     */
    function createCategory(&$data){
        $msg = 'Failed';
        if ( $this->tblCategory->create(&$data) ){
            $msg = 'Success';
        }
        return $msg;
    }
    /**
     * updateCategory
     *
     * @param mixed $data
     * @access public
     * @return void
     */
    function updateCategory(&$data){
        $msg = 'Failed';
        if ( $this->tblCategory->update(&$data) ){
            $msg = 'Success';
        }
        return $msg;
    }

    /**
     * removeCategory
     *
     * @param mixed $cate
     * @access public
     * @return void
     */
    function removeCategory($cate){
        $msg = 'Failed';
        if ( $this->tblCategory->removeByPkv($cate) )
            $msg = 'Success';
        return $msg;
    }

    /**
     * removeCategories
     *
     * @param mixed $cates
     * @access public
     * @return void
     */
    function removeCategories($cates){
        $msg = 'Failed';
        if ( $this->tblCategory->removeByPkvs($cates) )
            $msg = 'Success';
        return $msg;
    }
    /**
     * &getTable
     *
     * @access public
     * @return void
     */
    function &getTable()
    {
        return $this->tblCategory;
    }

}
